﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <link href="{{ asset('myadmin/css/plugins/dataTables/dataTables.bootstrap.css') }}" rel="stylesheet">
@stop
@section('content')
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>管理员信息： <small>所有管理员信息</small></h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                            <a class="dropdown-toggle" data-toggle="dropdown" href="table_data_tables.html#">
                                <i class="fa fa-wrench"></i>
                            </a>
                            <ul class="dropdown-menu dropdown-user">
                            </ul>
                            <a class="close-link">
                                <i class="fa fa-times"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr >
                                <th>序号</th>
                                <th style="display: none">id号</th>
                                <th >用户名</th>
                                <th >密码</th>
                                <th> 头像</th>
                                <th >ip地址</th>
                                <th >上次登录时间</th>
                                <th >等级</th>
                                <th >状态</th>
                                <th >&nbsp;&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($list as $v)
                                <tr align="center" id="tr" >
                                    <td>1</td>
                                    <td style="display: none">{{ $v->id }}</td>
                                    <td>{{$v->username}}</td>
                                    <td>保密</td>
                                    @if (count($v->pic))
                                        <td><a data-toggle="modal"  href="#modal-form-photo" onclick="editImg(this)"><img src="{{ url('/upload/admin/'.$v->pic) }}" width="60" onclick="subHid(this)"></a></td>
                                    @else
                                        <td><a  data-toggle="modal" class="btn btn-primary" href="#modal-form-photo" onclick="subHid(this)">添加图片</a></td>
                                    @endif
                                    <td>{{$v->ip}}</td>
                                    <td>{{$v->ltime}}</td>
                                    <td>
                                        @if ($v->level == 1)     普通管理员
                                        @else      <b>超级管理员</b>       @endif
                                    </td>
                                    <td>
                                        @if ($v->status == 1)
                                            正常&nbsp;|&nbsp;<a onclick="setstatus({{ $v->id }},{{ $v->status }}, this)" id="z" >更改</a>
                                        @else
                                            冻结&nbsp;|&nbsp;<a onclick="setstatus({{ $v->id }},{{ $v->status }}, this)"  id="d" >更改</a>
                                        @endif
                                    </td>
                                    <td>


                                            <a href="{{ url('admin/super/'.$v->id.'/edit') }}">修改</a> |
                                        <a onclick="javascript:dodelete(this);" data-toggle="modal" class="" href="#modal-form-one"  >删除</a>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>
    <div id="modal-form-photo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <button class="close"
                                    data-dismiss="modal">&times;
                            </button>
                            <h3 class="m-t-none m-b" id="up_img">添加图片</h3>

                            <form action='/admin/super/editLogo' method='post' enctype='multipart/form-data'>
                                <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                                <input type='hidden' name='id' id="hid">
                                <div class="list list-title">
                                    <li class="head"><i>我的头像：</i><img id="pic" src="" width="80"><input style="display: none" type="file" id="img" name="photo" ><button type="button" onclick="demo();"  >点击上传<br></button></li>
                                    </ul>

                                </div>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
                                ><strong>提交</strong>
                                </button>
                            </form>



                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mainly scripts -->
@stop
@section('script')
    <script type="text/javascript" src="{{ asset('myadmin/js/jquery.min.js') }}"></script><script type="text/javascript"  src="{{ asset('myadmin/js/jquery-2.1.1.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/bootstrap.min.js?v=3.4.0') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/metisMenu/jquery.metisMenu.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/slimscroll/jquery.slimscroll.min.js') }}"></script>
    <!-- iCheck -->
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/iCheck/icheck.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>

    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/jeditable/jquery.jeditable.js') }}"></script>

    <!-- Data Tables -->
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dataTables/jquery.dataTables.js') }}"></script>
    <script type="text/javascript" src="{{ asset('myadmin/js/plugins/dataTables/dataTables.bootstrap.js') }}"></script>
    <script type="text/javascript">
        function setstatus(id,status, bn){


            if(confirm("你确定要修改吗？")){
                var sts=(status==1)?2:1;
                $.ajax({
                    url:'{{ url("/admin/super/setstatus") }}',
                    async:false,				//是否异步
                    type:'post',				//请求方式
                    data:{id:id, status:sts, _token:"{{  csrf_token() }}"},				//发送的数据
                    dataType:'json',			//响应的数据类型
                    success:function(data)		//成功时回调函数
                    {
                        if(sts == 2){
                            $(bn).parent().html('冻结&nbsp;|&nbsp;<a onclick="setstatus('+id+',1, this)" >更改</a>');

                        }else{
                            $(bn).parent().html('正常&nbsp;|&nbsp;<a onclick="setstatus('+id+',2, this)" >更改</a>');
//                            $(bn).remove();
                        }
                    }
                });
            }
        }

        function dodelete(obj)
        {
//                alert(111);

           var id=$(obj).parent().parent().children('td').eq(1).html();
//           var str1="/admin/super/"+id;
            $.ajax({
                url: '{{url("/admin/super/delete")}}',
                type: 'POST',
                dataType: 'json',
                cache: false,
                data: { _token: "{{ csrf_token() }}", id: id },
                success: function (data) {
//                    console.log(data);
                    $(obj).parent().parent().css('display','none');
                },
                error: function (data) {
//                                alert("删除时候确认以后ajax提交删除功能没有实现");
                },
            });

        }


        $(document).ready(function () {
            $('.dataTables-example').dataTable();
            var oTable = $('#editable').dataTable();
            oTable.$('td').editable('../example_ajax.php', {
                "callback": function (sValue, y) {
                    var aPos = oTable.fnGetPosition(this);
                    oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                },
                "submitdata": function (value, settings) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition(this)[2]
                    };
                },
                "width": "90%",
                "height": "100%"
            });
        });
        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }

        function subHid(obj) {
            //获取原节点id
            hid =$(obj).parentsUntil('#tbody').children('td').eq(1).html();;
            did =  $(obj).parent().parent().attr('id');
            src = $(obj).attr('src');
            //把原节点名添加到模态框
            $('#pic').attr('src',src);
            //把原节点名添加到模态框
            $('#hid').val(hid);
        }

        function editImg(obj){
            //did =  $(obj).parent().parent().attr('id');
            $('#up_img').html('更改图片');

        }
    </script>

@stop